#include<iostream>
#include<algorithm>

using namespace std;

typedef long long LL;

const int N=1e5+10;

int g[N],h[N];
int n;


int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) cin>>g[i],h[g[i]]++;
	
	LL sum=0;
	for(int i=n;i>=1;i--){
		if(h[i]&&h[i+1]){
			if((LL)i*h[i]>=(LL)(i-1)*h[i-1]+(LL)(i+1)*h[i+1]){
				sum+=(LL)i*h[i];
				h[i-1]=0,h[i+1]=0;
			}
			else{
				sum+=(LL)(i-1)*h[i-1]+(LL)(i+1)*h[i+1];
				h[i]=0,h[i-1]=0,h[i+1]=0;
			}
		}
	}
	
	cout<<sum<<endl;
	
	return 0;
}
